package com.zbf.auth.mapper;

import com.zbf.common.entity.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/8/26 20:28
 * 描述:
 */
@Mapper
public interface UserDao {

    @Select("select * from base_user where loginName=#{userName}")
    public Map<String, Object> getUserByUserName(String userName);


    /**
     * 参数：
     * 返回值：
     * 描述: 获取当前user的所有的角色
     */
    @Select("select UPPER(br.role_code) roleCode from base_role br INNER JOIN base_user_role bur ON br.id=bur.roleId where bur.userId=#{userId}")
    public List<String> getUserRole(Long userId);

    /**
     * 依据手机号获取当前user
     * @param phoneNum 手机号
     * @return
     */
    @Select("select * from base_user where tel=#{phoneNum}")
    public Map<String, Object> getUserByUserTel(String phoneNum);

    /**
     * 依据邮箱获取当前user
     * @param email
     * @return
     */
    @Select("select * from base_user where email=#{email}")
    public Map<String, Object> getUserByUserEmail(String email);

    @Insert("insert into base_user (userName,loginName,passWord,tel,email,sex)values(#{userName}," +
            "#{loginName},#{passWord},#{tel},#{email},#{sex})")
    public boolean insertUser(UserEntity userEntity);

    @Update("update base_user set passWord = #{pwd} where tel=#{tel}")
    public boolean updatePwd(String pwd,String tel);

}